package com.xzx.study.animation;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;
import com.xzx.study.R;

public class AnimationApp1Activity extends AppCompatActivity {

    private RelativeLayout animation_app1_welcome_layout;
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 1) {
                startActivity(new Intent(AnimationApp1Activity.this, Setup1Activity.class));
                finish();
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation_app1);

        animation_app1_welcome_layout = findViewById(R.id.animation_app1_welcome_layout);
        showAnimation();
        handler.sendEmptyMessageDelayed(1, 2000);
    }

    private void showAnimation() {
        AnimationSet animationSet = new AnimationSet(false);

        RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
                                                              Animation.RELATIVE_TO_SELF, 0.5f);
        animationSet.addAnimation(rotateAnimation);

        AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
        animationSet.addAnimation(alphaAnimation);

        ScaleAnimation scaleAnimation = new ScaleAnimation(0f, 1f, 0, 1f, Animation.RELATIVE_TO_SELF, 0.5f,
                                                           Animation.RELATIVE_TO_SELF, 0.5f);
        animationSet.addAnimation(scaleAnimation);

        animationSet.setDuration(2000);
        animation_app1_welcome_layout.startAnimation(animationSet);
    }
}
